<?php
/**
 * 小说Dao
 */

class Dao_NovelBookcaseModel extends Dao_BaseModel {

    protected $_table = 'bookcase';

    const NORMAL_STATUS = 1;
    const REDIS_KEYWORD = 'USER_KEY_';
    const EXTIME        = '86400';

    public function __construct ()
    {
        parent::__construct ();
    }
    
    /**
     * 获取书架信息
     */
    public function getUserInfo($wheres = [])
    {
        $where   = array ();
        if(isset( $wheres['user_phone'] )){
            $where[] = array ( 'user_phone' , $wheres['user_phone'] );
        }
        
        if(isset( $wheres['user_id'] )){
            $where[] = array ( 'user_id' , $wheres['user_id'] );
        }
        
        $where[] = array ( 'user_status' , self::NORMAL_STATUS );
        $info = parent::getOne( array ( 'user_id' , 'user_nickname' , 'user_phone' , 'user_sex' , 'user_age' , 'user_address' ) , $where );
        return $info;
    }
    
    /**
     * 检查是否在书架中
     */
    public function checkInBookCase( $novelid = 0 , $uid = 0 )
    {
        if( !$novelid || !$uid ){
            return 1;
        }
        $where  = array ();
        $where[] = array ( 'case_user_id' , $uid );
        $where[] = array ( 'case_novel_id' , $novelid );
        $info = parent::getOne( array ( 'case_id' ) , $where );
        return $info ? 2 : 1;
    }
    
    /**
     * 获取用户书架
     */
    public function getUserBookCase( $uid = 0 )
    {
        if( !$uid ){
            return [];
        }
        $where    = array ();
        $where[]  = array ( 'case_user_id' , $uid );
        $info     = parent::getRows( array ( 'case_novel_id' ) , $where );
        return $info ? $info : [];
    }
    
    /**
     * 新增小说
     */
    public function addBook($data)
    {
        $info = parent::add ( $data );
        return $info;
    }
    
    /**
     * 删除小说
     */
    public function delBook($data)
    {
        $info = parent::del ( $data );
        return $info;
    }
    
}
